package cn.fastoo.common.dao.product;
import cn.fastoo.common.entity.product.ProductAttr;
import cn.fastoo.common.entity.product.ProductAttrValue;
import cn.fastoo.common.entity.product.ProductCategory;
import cn.fastoo.common.sampleframe.dao.FastDao;
import cn.fastoo.common.sampleframe.dao.impl.FastDaoImpl;
import cn.fastoo.common.sampleframe.search.Search;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.sql.DataSource;


@Component
@Transactional
public class ProductAttrDao extends FastDaoImpl<ProductAttr> implements FastDao<ProductAttr> {


    public Logger logger = LoggerFactory.getLogger(ProductAttrDao.class);

    @Autowired
    @Qualifier("mainDS")
    private void setJt(DataSource ds){
        this.jt = new JdbcTemplate(ds);
    }


    @Override
    public void insert(ProductAttr productAttr) {
        super.insert(productAttr);
        /*
        //增加所有商品
        jt.update("INSERT INTO product_attr_value(`product_id`, `product_attr_id`)\n" +
                "select p.id,\n" +
                "       pa.id as pa_id\n" +
                "  from `product` p,\n" +
                "       `product_attr` pa\n" +
                " where pa.id= ?",productAttr.getId());*/
    }

    public void insertByProductId(Long productId) {
        //增加所有商品
        /*
        jt.update("INSERT INTO product_attr_value(`product_id`, `product_attr_id`)\n" +
                "select p.id,\n" +
                "       pa.id as pa_id\n" +
                "  from `product` p,\n" +
                "       `product_attr` pa\n" +
                " where p.id= ?",productId);*/
    }
    @Override
    public void delete(ProductAttr productAttr) {
        super.delete(productAttr);
        //jt.update(" delete from product_attr_value where product_attr_id = ?",productAttr.getId());
    }


}
